package com.fileshare.web.service.impl;

import com.fileshare.web.entity.Category;
import com.fileshare.web.service.CategoryService;
import com.fileshare.web.service.WebPageService;
import com.fileshare.web.utils.DateUtil;
import com.fileshare.web.utils.SystemUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class WebPageServiceImpl implements WebPageService {
    @Resource
    private CategoryService categoryService;

    @Override
    public String renderMarkdown(String markdown) {
        if (StringUtils.isNotBlank(markdown)) {
            markdown = markdown.replace("<!--more-->", "\r\n");
            return SystemUtil.mdToHtml(markdown);
        }
        return "";
    }

    @Override
    public String fmtDate(Date date) {
        return DateUtil.format(date);
    }

    @Override
    public String fmtDate(Date date, String pattern) {
        return DateUtil.format(date, pattern);
    }

    @Override
    public List<Category> getCategories() {
        return categoryService.findCategories(0);
    }
}
